using System.Collections.ObjectModel;
using Core.GameObjects.States;
using Microsoft.Xna.Framework;

namespace Core.GameObjects
{
    /// <summary>
    /// The Basic Abstract Class that all Game Objects Derive From
    /// </summary>
    public abstract class GameObject
    {
        public Point WorldCoordinate { get { return _WorldCoordinate; } set { _WorldCoordinate = value; } }
        public Vector2 Position { get; protected set; }
        public string Name { get; set; }
        public int ID { get; set; }
        public string Description { get; set; }

        public bool Visible { get; set; }
        public bool Enabled { get; set; }

        public StateMachine StateMachine { get; protected set; }
        
        protected Collection<GameObject> _ChildObjects;
        protected Point _WorldCoordinate;

        public GameObject(int id, string name)
        {
            CreateGameObject(id, name, "");
        }

        public GameObject(int id, string name, string description)
        {
            CreateGameObject(id, name, description);
        }

        private void CreateGameObject(int id, string name, string description)
        {
            ID = id;
            Name = name;
            Description = description;
            Position = new Vector2(0, 0);
            _ChildObjects = new Collection<GameObject>();

            //Setup the State Machine;
            StateMachine = new StateMachine(this);
        }

        public virtual void Update(GameTime gameTime)
        {
            //Update the current state
            StateMachine.Update();

            foreach (GameObject go in _ChildObjects)
            {
                if(go != null)
                    go.Update(gameTime);
            }
        }
    }
}
